public class BoardLocation {
	final static int UP = 0;
	final static int RIGHT = 1;
	final static int DOWN = 2;
	final static int LEFT = 3;
	
	final static int UP_RIGHT = 4;
	final static int DOWN_RIGHT = 5;
	final static int DOWN_LEFT = 6;
	final static int UP_LEFT = 7;

	private int col;
	private int row;

	// Create a BoardLocation with a row and column
	public BoardLocation(int row, int col) {
		super();
		this.col = col;
		this.row = row;
	}

	public BoardLocation(String location) {
		super();
		this.col = location.charAt(0) - 'a';
		this.row = 8 - (Integer.valueOf(location.substring(1, 2)));
	}

	// Getters
	public int getRow() {
		return row;
	}

	public int getCol() {
		return col;
	}

	// Setters, probably shouldn't be needed
	public void setRow(int row) {
		this.row = row;
	}

	public void setCol(int col) {
		this.col = col;
	}

	// Return direction of move from this -> dest
	public int getMoveDirection(BoardLocation dest) {
		int direction = -1;
		
		if(dest.getCol() == this.getCol()) {
			if(dest.getRow() > this.getRow()) {
				direction = UP; 
			} else if(dest.getRow() < this.getRow()) {
				direction = DOWN;
			}
		} else if(dest.getRow() == this.getRow()) {
			if(dest.getCol() > this.getCol()) {
				direction = RIGHT;
			} else if(dest.getCol() < this.getCol()) {
				direction = LEFT;
			}
		} else if(dest.getCol() > this.getCol()) {
			if(dest.getRow() > this.getRow()) {
				direction = DOWN_RIGHT;
			} else if(dest.getRow() < this.getRow()) {
				direction = UP_LEFT;
			}
		} else if(dest.getCol() < this.getCol()) {
			if(dest.getRow() > this.getRow()) {
				direction = DOWN_LEFT;
			} else if(dest.getRow() < this.getRow()) {
				direction = UP_RIGHT;
			}
		}
		
		return direction;
	}

	// Get length of move in squares from this -> dest
	// Length defined as floor of the square of the distance
	public int getMoveLength(BoardLocation dest) {
		return (int) Math.floor(Math.sqrt(Math.pow(dest.getCol() - col, 2)
				+ Math.pow(dest.getRow() - row, 2)));
	}

	// Returns whether or not this location is on the board
	public boolean isOnBoard() {
		return col >= 0 && row >= 0 && col < 8 && row < 8;
	}

	// Prints out this location in standard chess notation
	public String toString() {
		return ((char) 'a' + col) + (row + 1) + "";
	}
}
